<?php
use think\exception\HttpResponseException;
use app\common\exception\NormalException;
use app\common\model\SystemInfo;

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件

/**
 * 抛出错误并立刻返回
 *
 * @param string $message 错误信息
 * @param int $code 错误代码
 */
function error($message = '服务器异常', $code = 500)
{
    throw new NormalException($message, $code);
}

/**
 * 获取当前登录的用户
 *
 * @return \app\common\model\User
 */
function getCurrentUser()
{
    return \app\index\controller\Auth::getUserFromSession();
}

/**
 * 获取或者设置系统变量
 *
 * @param string $key 键名
 * @param mixed $value 值，null则为获取
 */
function systeminfo($key, $value = null)
{
    if ($value === null) {
        return SystemInfo::get($key);
    } else {
        return SystemInfo::set($key, $value);
    }
}
